package com.czr.controller.collect;

import com.czr.entity.Collect;
import com.czr.service.collect.CollectService;
import com.czr.vo.CollectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Description:
 * Author: czr Administrator
 * Version: 1.0
 * Create Date Time: 2021/12/13 13:08.
 * Update Date Time:
 *
 */
@Controller
public class CollectController {

    @Autowired
    private CollectService collectServiceImpl;

    @GetMapping(value = {"/","/index"})
    public String collect() {
        return "/collect/index";
    }

    @PostMapping("/api/collect/del/{id}")
    @ResponseBody
    public boolean delCollect(@PathVariable("id") Long id) {
        return collectServiceImpl.removeById(id);
    }

    /**
     * 归档查询
     * @return
     */
    @GetMapping("/api/collect/load")
    @ResponseBody
    public List<CollectVo> findCollect() {
        return collectServiceImpl.findList();
    }



    /**
     * 保存和修改收藏夹
     * @return
     */
    @PostMapping("/api/collect/saveupdate")
    @ResponseBody
    public Collect saveupdate(@RequestBody Collect collect) {
        boolean flag = collectServiceImpl.saveOrUpdate(collect);
        return flag ? collect : null;
    }


}
